﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using SlaughterItem.Common.Domains.ListWeek2;
using SlaughterItem.Common.Dtos;
using SlaughterItem.Common.Infrastructures.Interfaces;
using SlaughterItem.Enum;

namespace GetSlaughterItem.API.Application.Commands.Week02.BasicSettings
{
    //分割领用反填
    public class SplitRequisManageHandler : IRequestHandler<SplitRequisManageCommend, Result>
    {
        private readonly IBaseRepositoryGet<SplitRequis> SplitRequis;

        public SplitRequisManageHandler(IBaseRepositoryGet<SplitRequis> SplitRequis)
        {
            this.SplitRequis = SplitRequis;
        }

        public async Task<Result> Handle(SplitRequisManageCommend request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCode.Search };
            try
            {
                var list = await SplitRequis.GetAll().Where(x => x.SplitRequisId == request.SplitRequisId).FirstOrDefaultAsync();

                if (list != null)
                {
                    result.Code = (int)CommonErrorCode.Success;
                    result.Data = list;
                    result.Msg = "反填成功";
                }
            }
            catch (Exception)
            {

                throw;
            }
            return result;
        }
    }
}
